package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.condition.SysRegionQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.framework.dto.SysRegionDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.constant.SysOrgConstant;
import cmm.user.facade.system.dto.SysOrgDTO;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.product.service.ISplInfoService;
import cn.fl.product.vo.SplInfoVO;
import cn.fl.project.condition.PrjQuatPrpsAttrQueryCondition;
import cn.fl.project.dto.PrjQuatPrpsAttrDTO;
import cn.fl.project.service.IPrjQuatPrpsAttrService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.transform.PrjQuatPrpsAttrVOTransform;
import cn.fl.project.vo.PrjQuatPrpsAttrPageVO;
import cn.fl.project.vo.PrjQuatPrpsAttrVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.transform.SysCdMapDVOTransform;
import cn.fl.system.vo.SysCdMapDVO;
import com.alibaba.fastjson.JSON;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 项目报价方案配置属性表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Slf4j
@Service
public class PrjQuatPrpsAttrServiceImpl implements IPrjQuatPrpsAttrService {

	private static ExtSlf4jLogger logger = ExtSlf4jLoggerBuilder.create()
			.setLogger(log).setBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setLogType(LogTypeEnum.BUSINESS).build().setKeywords("PrjQuatPrpsAttr");
	/**
	 * 项目服务接口
	 */
	@Autowired
	private IProjectApiService projectApiService;
	/**
	 * 映射表API服务
	 */
	@Autowired
	private ISysCdMapApiService sysCdMapApiService;
	
	/**
	 * 本地数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 本地供应商服务
	 */
	@Autowired
	private ISplInfoService splInfoService;
	
	/**
	 * 区域 服务
	 */
	@Autowired
	private ISysRegionApiService sysRegionApiService;
	
	/**
	 * 组织架构接口
	 */
	@Autowired
	private ISysOrgApiService sysOrgApiService;

    @Autowired
    IFriBaseInfoService friBaseInfoService;

	@Override
	public PrjQuatPrpsAttrVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return null;
		}
		PrjQuatPrpsAttrDTO dto = null;//this.自定义ApiService.selectById(id);
		return PrjQuatPrpsAttrVOTransform.toVO(dto);
	}

	@Override
	public Long add(PrjQuatPrpsAttrVO entity) throws BaseException{
		if(null == entity){
			return null;
		}
		//return this.prjQuatPrpsAttrApiService.add(PrjQuatPrpsAttrVOTransform.toDTO(entity));
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return false;
		}
		//return this.prjQuatPrpsAttrApiService.removeById(id);
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(PrjQuatPrpsAttrVO entity) throws BaseException{
		if(null == entity){
			return false;
		}
		//return this.prjQuatPrpsAttrApiService.modify(PrjQuatPrpsAttrVOTransform.toDTO(entity));
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.prjQuatPrpsAttrApiService.searchListPage(page);
		return null;
	}

	@Override
	public List<KeyValueVO> searchBusinessTypCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_PRJ_BIZ_TYP_CD);
	}

	@Override
	public List<KeyValueVO> searchPrjTypCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_PRJ_TYPE_CD);
	}

	@Override
	public List<KeyValueVO> searchBizResCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_PRJ_BIZ_RES_CD);
	}
	
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			logger.error("获取字典项组失败,msg:{}",e.getMessage());
		} catch (Exception e) {
			logger.error("获取字典项组失败,系统异常,msg:{}",e.getMessage());
		}
		return kvList;
	}

	@Override
	public List<KeyValueVO> searchSplTypCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_PRJ_SPL_TYP_CD);
	}
	
	@Override
	public List<KeyValueVO> searchYesOrNoCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_SYS_YES_NO_CD);
	}

	@Override
	public List<KeyValueVO> searchBrCdList() throws BaseException {
		List<SysDictionaryDTO> searchGroupList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRD_TYP_CATEGORY);
		List<String> sCodeList = new ArrayList<String>();
		if(CollectionUtils.isNotEmpty(searchGroupList)){
			for (SysDictionaryDTO sysDictionaryDTO : searchGroupList) {
				String code = sysDictionaryDTO.getCode();
				if(!sCodeList.contains(code)){
					sCodeList.add(code);
				}
			}
		}
		String mTypCd = "M0002";
		String sGrpCd = DictionaryConstant.CODE_PRD_TYP_CATEGORY;
		SysCdMapDQueryCondition condition = new SysCdMapDQueryCondition();
		List<KeyValueVO> brCdKVList = new ArrayList<KeyValueVO>();
		if(CollectionUtils.isNotEmpty(sCodeList)){
			//1、系统代码 2、组织架构代码 3、映射类型代码(代码映射表中) 4、原代码组值(代码映射表中) 5、原代码值(代码映射表中) 
			condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
			condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			condition.setmTypCd(mTypCd);
			//condition.setsGrpCd(sGrpCd);
			condition.setsCodeList(sCodeList);
			List<SysCdMapDDTO> listDTO = this.sysCdMapApiService.searchSysCdMapDWithTargetList(condition);
			List<SysCdMapDVO> list = SysCdMapDVOTransform.toVOList(listDTO);
			//List<SysCdMapDVO> list = this.prdBscInfoService.searchSysCdMapDList(condition);
			if(CollectionUtils.isNotEmpty(list)){
				for (SysCdMapDVO sysCdMapDVO : list) {
					KeyValueVO kv = new KeyValueVO();
					kv.setKey(sysCdMapDVO.getTCode());
					kv.setValue(sysCdMapDVO.getTCodeNm());
					brCdKVList.add(kv);
				}
			}
		}
		return brCdKVList;
	}

	@Override
	public Boolean addBatch(List<PrjQuatPrpsAttrVO> prjQuatPrpsAttrVOList,Long prpsCfgId) throws BaseException {
		if(CollectionUtils.isEmpty(prjQuatPrpsAttrVOList)){
			logger.info("批量信息方案配置属性集合不能为空,prpsCfgId:{}",prpsCfgId);
			return false;
		};
		return this.projectApiService.addPrjQuatPrpsAttrBatch(PrjQuatPrpsAttrVOTransform.toDTOList(prjQuatPrpsAttrVOList), prpsCfgId);
	}

	@Override
	public PrjQuatPrpsAttrPageVO selectPrjQuatPrpsAttrPageVOById(Long prpsCfgId) throws BaseException {
		if(StringUtils.isEmpty(prpsCfgId)){
			logger.info("查询方案配置属性,方案ID不能为空,prpsCfgId");
			return null;
		};
		String sysCd = CurrentThreadContext.getCurrentSysCd();
		String currOrgCd = CurrentThreadContext.getCurrentOrgCd();
		PrjQuatPrpsAttrQueryCondition qc = new PrjQuatPrpsAttrQueryCondition();
		qc.setPrpsCfgId(prpsCfgId);
		List<PrjQuatPrpsAttrDTO> prjQuatPrpsAttrDTOList = this.projectApiService.searchPrjQuatPrpsAttrList(qc);
		if(CollectionUtils.isEmpty(prjQuatPrpsAttrDTOList)){
			return null;
		}
		//处理数据
		//数据字典方案配置属性List
		List<SysDictionaryDTO> searchGroup = this.sysDictionaryApiService.searchGroup(sysCd, currOrgCd, DictionaryConstant.CODE_PRJ_QUAT_CFG_ATTR_CD);
		String bizTypCd_attrCd = "", prjTypCd_attrCd = "", bizResCd_attrCd = "", splTypCd_attrCd = "",
		       isGrpOrder_attrCd = "", brCd_attrCd = "", prdTypCd_attrCd = "", splIds_attrCd = "", prdMdls_attrCd = "",
		       rgnPrCd_attrCd="",rgnCyCd_attrCd="",orgCd_attrCd = "",friBaseOrgCd_attrCd = "" ;
		if(CollectionUtils.isNotEmpty(searchGroup)){
			for (SysDictionaryDTO sysDictionaryDTO : searchGroup) {
				if("bizTypCd".equals(sysDictionaryDTO.getCodeAttr1())){//业务类型bizTypCd
					bizTypCd_attrCd = sysDictionaryDTO.getCode();
				}else if("prjTypCd".equals(sysDictionaryDTO.getCodeAttr1())){//项目类型prjTypCd
					prjTypCd_attrCd = sysDictionaryDTO.getCode();
				}else if("bizResCd".equals(sysDictionaryDTO.getCodeAttr1())){//业务来源bizResCd
					bizResCd_attrCd = sysDictionaryDTO.getCode();
				}else if("splTypCd".equals(sysDictionaryDTO.getCodeAttr1())){//供应商类型splTypCd
					splTypCd_attrCd = sysDictionaryDTO.getCode();
				}else if("isGrpOrder".equals(sysDictionaryDTO.getCodeAttr1())){//是否团单isGrpOrder
					isGrpOrder_attrCd = sysDictionaryDTO.getCode();
				}else if("brCd".equals(sysDictionaryDTO.getCodeAttr1())){//产品品牌brCd
					brCd_attrCd = sysDictionaryDTO.getCode();
				}else if("prdTypCd".equals(sysDictionaryDTO.getCodeAttr1())){//产品类型prdTypCd
					prdTypCd_attrCd = sysDictionaryDTO.getCode();
				}else if("splIds".equals(sysDictionaryDTO.getCodeAttr1())){//供应商splIds
					splIds_attrCd = sysDictionaryDTO.getCode();
				}else if("prdMdl".equals(sysDictionaryDTO.getCodeAttr1())){//产品型号prdMdls
					prdMdls_attrCd = sysDictionaryDTO.getCode();
				}else if("rgnPrCd".equals(sysDictionaryDTO.getCodeAttr1())){//产品型号prdMdls
					rgnPrCd_attrCd = sysDictionaryDTO.getCode();
				}else if("rgnCyCd".equals(sysDictionaryDTO.getCodeAttr1())){//产品型号prdMdls
					rgnCyCd_attrCd = sysDictionaryDTO.getCode();
				}else if("orgCd".equals(sysDictionaryDTO.getCodeAttr1())){//组织架构orgCd
					orgCd_attrCd = sysDictionaryDTO.getCode();
				} else if ("friBaseOrgCd".equals(sysDictionaryDTO.getCodeAttr1())) { //所属机构
                    friBaseOrgCd_attrCd = sysDictionaryDTO.getCode();
                }
			}
		}
		PrjQuatPrpsAttrPageVO prjQuatPrpsAttrPageVO = new PrjQuatPrpsAttrPageVO();
		String bizTypCd="",prjTypCd="",bizResCd="",splTypCd="",isGrpOrder="",brCd="",prdTypCd="", splIds="",prdMdls="",rgnPrCd="",
                rgnCyCd="",orgCd="", friBaseOrgCd="";
		String bizTypCd_flag="",prjTypCd_flag="",bizResCd_flag="",splTypCd_flag="",isGrpOrder_flag="", brCd_flag="",prdTypCd_flag="",
                splIds_flag="",prdMdls_flag="",rgnPrCd_flag="",rgnCyCd_flag="",orgCd_flag="",friBaseOrgCd_flag="";
		String bizTypCdNm="",prjTypCdNm="",bizResCdNm="",splTypCdNm="",isGrpOrderNm="",brCdNm="",prdTypCdNm="",splIdsNm="",prdMdlsNm="",
                rgnPrCdNm="",rgnCyCdNm="",orgNm="",friBaseOrgCdNm="";
		Map<String, String> bizTypCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, currOrgCd, DictionaryConstant.CODE_PRJ_BIZ_TYP_CD);
		Map<String, String> prjTypCdMap = this.sysDictionaryApiService.searchGroupToMapAll(sysCd, currOrgCd, DictionaryConstant.CODE_PRJ_TYPE_CD);
		Map<String, String> bizResCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, currOrgCd, DictionaryConstant.CODE_PRJ_BIZ_RES_CD);
		Map<String, String> splTypCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, currOrgCd, DictionaryConstant.CODE_PRJ_SPL_TYP_CD);
		Map<String, String> yesNoCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, currOrgCd, DictionaryConstant.CODE_SYS_YES_NO_CD);
		//Map<String, String> brCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, DictionaryConstant.CODE_PRD_BR_CD);
		Map<String, String> brCdMap = new HashMap<String, String>();
		List<KeyValueVO> brCdList = this.searchBrCdList();
		if(CollectionUtils.isNotEmpty(brCdList)){
			for (KeyValueVO keyValueVO : brCdList) {
				brCdMap.put(keyValueVO.getKey(), keyValueVO.getValue());
			}
		}
		Map<String, String> prdTypCdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, currOrgCd, DictionaryConstant.CODE_PRD_TYE_CD);
		List<SysOrgDTO> sysOrgDTOList = this.sysOrgApiService.searchSysBuOrgListWithChild(SysOrgConstant.SYS_ORG_ORG_TYP_CD_IS_BUSI, CurrentThreadContext.getCurrentSysCd());
		List<SysRegionDTO> regionList = this.sysRegionApiService.searchRegionList(new SysRegionQueryCondition());
        FriBaseInfoQueryCondition friBaseInfoQueryCondition = new FriBaseInfoQueryCondition();
        friBaseInfoQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        friBaseInfoQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        friBaseInfoQueryCondition.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
        friBaseInfoQueryCondition.setInsUseCd("2");
        List<FriBaseInfoVO> friBaseInfoVOList = friBaseInfoService.searchList(friBaseInfoQueryCondition);
		for (PrjQuatPrpsAttrDTO prjQuatPrpsAttrDTO : prjQuatPrpsAttrDTOList) {
			if(bizTypCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				bizTypCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				bizTypCd += prjQuatPrpsAttrDTO.getAttrVal();
				bizTypCd += ";";
				if(bizTypCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					bizTypCdNm += bizTypCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					bizTypCdNm += ";";
				}
			}else if(prjTypCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				prjTypCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				prjTypCd += prjQuatPrpsAttrDTO.getAttrVal();
				prjTypCd += ";";
				if(prjTypCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					prjTypCdNm += prjTypCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					prjTypCdNm += ";";
				}
			}else if(bizResCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				bizResCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				bizResCd += prjQuatPrpsAttrDTO.getAttrVal();
				bizResCd += ";";
				if(bizResCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					bizResCdNm += bizResCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					bizResCdNm += ";";
				}
			}else if(splTypCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				splTypCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				splTypCd += prjQuatPrpsAttrDTO.getAttrVal();
				splTypCd += ";";
				if(splTypCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					splTypCdNm += splTypCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					splTypCdNm += ";";
				}
			}else if(isGrpOrder_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				isGrpOrder_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				isGrpOrder += prjQuatPrpsAttrDTO.getAttrVal();
				isGrpOrder += ";";
				if(yesNoCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					isGrpOrderNm += yesNoCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					isGrpOrderNm += ";";
				}
			}else if(brCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				brCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				brCd += prjQuatPrpsAttrDTO.getAttrVal();
				brCd += ";";
				if(brCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					brCdNm += brCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					brCdNm += ";";
				}
			}else if(prdTypCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				prdTypCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				prdTypCd += prjQuatPrpsAttrDTO.getAttrVal();
				prdTypCd += ";";
				if(prdTypCdMap.containsKey(prjQuatPrpsAttrDTO.getAttrVal())){
					prdTypCdNm += prdTypCdMap.get(prjQuatPrpsAttrDTO.getAttrVal());
					prdTypCdNm += ";";
				}
			}else if(splIds_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				splIds_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				splIds += prjQuatPrpsAttrDTO.getAttrVal();
				splIds += ";";
				String splId = prjQuatPrpsAttrDTO.getAttrVal();
				if(StringUtils.isNotEmpty(splId)){
					SplInfoVO splInfoVO = this.splInfoService.selectById(Long.valueOf(splId));
					splIdsNm += splInfoVO.getSplNm();
					splIdsNm += ";";
				}
			}else if(prdMdls_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				prdMdls_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				prdMdls += prjQuatPrpsAttrDTO.getAttrVal();
				prdMdls += ";";
				prdMdlsNm += prjQuatPrpsAttrDTO.getAttrVal();
				prdMdlsNm += ";";
			}else if(rgnPrCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				rgnPrCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				rgnPrCd += prjQuatPrpsAttrDTO.getAttrVal();
				rgnPrCd += ";";
				for (SysRegionDTO sysRegionDTO : regionList) {
					if(sysRegionDTO.getRgnCd().equals(prjQuatPrpsAttrDTO.getAttrVal())){
						rgnPrCdNm += sysRegionDTO.getRgnNm();
						rgnPrCdNm += ";";
					}
				}
			}else if(rgnCyCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				rgnCyCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				rgnCyCd += prjQuatPrpsAttrDTO.getAttrVal();
				rgnCyCd += ";";
				for (SysRegionDTO sysRegionDTO : regionList) {
					if(sysRegionDTO.getRgnCd().equals(prjQuatPrpsAttrDTO.getAttrVal())){
						rgnCyCdNm += sysRegionDTO.getRgnNm();
						rgnCyCdNm += ";";
					}
				}
			}else if(orgCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())){
				orgCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
				orgCd += prjQuatPrpsAttrDTO.getAttrVal();
				orgCd += ";";
				for (SysOrgDTO sysOrgDTO : sysOrgDTOList) {
					if(null!=prjQuatPrpsAttrDTO.getAttrVal() && prjQuatPrpsAttrDTO.getAttrVal().equals(sysOrgDTO.getOrgCd())){
						orgNm += sysOrgDTO.getOrgNm();
						orgNm += ";";
					}
				}
			} else if (friBaseOrgCd_attrCd.equals(prjQuatPrpsAttrDTO.getAttrCd())) {
                friBaseOrgCd_flag = prjQuatPrpsAttrDTO.getAttrTypCd();
                friBaseOrgCd += prjQuatPrpsAttrDTO.getAttrVal();
                friBaseOrgCd += ";";
                for (FriBaseInfoVO friBaseInfoVO : friBaseInfoVOList) {
                    if(null != prjQuatPrpsAttrDTO.getAttrVal() && prjQuatPrpsAttrDTO.getAttrVal().equals(friBaseInfoVO.getInsCode())){
                        friBaseOrgCdNm += friBaseInfoVO.getFundRasInsNm();
                        friBaseOrgCdNm += ";";
                    }
                }
            }
		}
		
		//设置是否参与配置标识
		prjQuatPrpsAttrPageVO.setBizTypCd_flag(bizTypCd_flag);
		prjQuatPrpsAttrPageVO.setPrjTypCd_flag(prjTypCd_flag);
		prjQuatPrpsAttrPageVO.setBizResCd_flag(bizResCd_flag);
		prjQuatPrpsAttrPageVO.setSplTypCd_flag(splTypCd_flag);
		prjQuatPrpsAttrPageVO.setIsGrpOrder_flag(isGrpOrder_flag);
		prjQuatPrpsAttrPageVO.setBrCd_flag(brCd_flag);
		prjQuatPrpsAttrPageVO.setPrdTypCd_flag(prdTypCd_flag);
		prjQuatPrpsAttrPageVO.setSplIds_flag(splIds_flag);
		prjQuatPrpsAttrPageVO.setPrdMdls_flag(prdMdls_flag);
		prjQuatPrpsAttrPageVO.setRgnPrCd_flag(rgnPrCd_flag);
		prjQuatPrpsAttrPageVO.setRgnCyCd_flag(rgnCyCd_flag);
		prjQuatPrpsAttrPageVO.setOrgCd_flag(orgCd_flag);
		prjQuatPrpsAttrPageVO.setFriBaseOrgCd_flag(friBaseOrgCd_flag);
		//---------------------------------------------------------------------------------------------
		if(StringUtils.isNotEmpty(bizTypCd)){
			prjQuatPrpsAttrPageVO.setBizTypCd(bizTypCd.substring(0, bizTypCd.length()-1));
		}
		if(StringUtils.isNotEmpty(bizTypCdNm)){
			prjQuatPrpsAttrPageVO.setBizTypCdNm(bizTypCdNm.substring(0, bizTypCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(prjTypCd)){
			prjQuatPrpsAttrPageVO.setPrjTypCd(prjTypCd.substring(0, prjTypCd.length()-1));
		}
		if(StringUtils.isNotEmpty(prjTypCdNm)){
			prjQuatPrpsAttrPageVO.setPrjTypCdNm(prjTypCdNm.substring(0, prjTypCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(bizResCd)){
			prjQuatPrpsAttrPageVO.setBizResCd(bizResCd.substring(0, bizResCd.length()-1));
		}
		if(StringUtils.isNotEmpty(bizResCdNm)){
			prjQuatPrpsAttrPageVO.setBizResCdNm(bizResCdNm.substring(0, bizResCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(splTypCd)){
			prjQuatPrpsAttrPageVO.setSplTypCd(splTypCd.substring(0, splTypCd.length()-1));
		}
		if(StringUtils.isNotEmpty(splTypCdNm)){
			prjQuatPrpsAttrPageVO.setSplTypCdNm(splTypCdNm.substring(0, splTypCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(isGrpOrder)){
			prjQuatPrpsAttrPageVO.setIsGrpOrder(isGrpOrder.substring(0, isGrpOrder.length()-1));
		}
		if(StringUtils.isNotEmpty(isGrpOrderNm)){
			prjQuatPrpsAttrPageVO.setIsGrpOrderNm(isGrpOrderNm.substring(0, isGrpOrderNm.length()-1));
		}
		if(StringUtils.isNotEmpty(brCd)){
			prjQuatPrpsAttrPageVO.setBrCd(brCd.substring(0, brCd.length()-1));
		}
		if(StringUtils.isNotEmpty(brCdNm)){
			prjQuatPrpsAttrPageVO.setBrCdNm(brCdNm.substring(0, brCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(prdTypCd)){
			prjQuatPrpsAttrPageVO.setPrdTypCd(prdTypCd.substring(0, prdTypCd.length()-1));
		}
		if(StringUtils.isNotEmpty(prdTypCdNm)){
			prjQuatPrpsAttrPageVO.setPrdTypCdNm(prdTypCdNm.substring(0, prdTypCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(splIds)){
			prjQuatPrpsAttrPageVO.setSplIds(splIds.substring(0, splIds.length()-1));
		}
		if(StringUtils.isNotEmpty(splIdsNm)){
			prjQuatPrpsAttrPageVO.setSplIdsNm(splIdsNm.substring(0, splIdsNm.length()-1));
		}
		if(StringUtils.isNotEmpty(prdMdls)){
			prjQuatPrpsAttrPageVO.setPrdMdls(prdMdls.substring(0, prdMdls.length()-1));
		}
		if(StringUtils.isNotEmpty(prdMdlsNm)){
			prjQuatPrpsAttrPageVO.setPrdMdlsNm(prdMdlsNm.substring(0, prdMdlsNm.length()-1));
		}
		if(StringUtils.isNotEmpty(rgnPrCd)){
			prjQuatPrpsAttrPageVO.setRgnPrCd(rgnPrCd.substring(0, rgnPrCd.length()-1));
		}
		if(StringUtils.isNotEmpty(rgnPrCdNm)){
			prjQuatPrpsAttrPageVO.setRgnPrCdNm(rgnPrCdNm.substring(0, rgnPrCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(rgnCyCd)){
			prjQuatPrpsAttrPageVO.setRgnCyCd(rgnCyCd.substring(0, rgnCyCd.length()-1));
		}
		if(StringUtils.isNotEmpty(rgnCyCdNm)){
			prjQuatPrpsAttrPageVO.setRgnCyCdNm(rgnCyCdNm.substring(0, rgnCyCdNm.length()-1));
		}
		if(StringUtils.isNotEmpty(orgCd)){
			prjQuatPrpsAttrPageVO.setOrgCd(orgCd.substring(0, orgCd.length()-1));
		}
		if(StringUtils.isNotEmpty(orgNm)){
			prjQuatPrpsAttrPageVO.setOrgNm(orgNm.substring(0, orgNm.length()-1));
		}
        if(StringUtils.isNotEmpty(friBaseOrgCd)){
            prjQuatPrpsAttrPageVO.setFriBaseOrgCd(friBaseOrgCd.substring(0, friBaseOrgCd.length() - 1));
        }
        if(StringUtils.isNotEmpty(friBaseOrgCdNm)){
            prjQuatPrpsAttrPageVO.setFriBaseOrgCdNm(friBaseOrgCdNm.substring(0, friBaseOrgCdNm.length() - 1));
        }
		return prjQuatPrpsAttrPageVO;
	}

	@Override
	public List<KeyValueVO> searchRegionProvinceList() throws BaseException {
		String sysCd = CurrentThreadContext.getCurrentSysCd();
		List<KeyValueVO> kvList = new ArrayList<KeyValueVO>();
		List<SysRegionDTO> provinceList = this.sysRegionApiService.searchProvinceList(sysCd);
		if(CollectionUtils.isNotEmpty(provinceList)){
			for (SysRegionDTO sysRegionDTO : provinceList) {
				KeyValueVO kv = new KeyValueVO();
				kv.setKey(sysRegionDTO.getRgnCd());
				kv.setValue(sysRegionDTO.getRgnNm());
				kvList.add(kv);
			}
		}
		return kvList;
	}

	@Override
	public JSONArray searchRegionJSONArray() throws BaseException {
		List<SysRegionDTO> regionList = this.sysRegionApiService.searchRegionList(new SysRegionQueryCondition()); 
		List<SysRegionDTO> rgnList = new ArrayList<SysRegionDTO>();
		if(CollectionUtils.isNotEmpty(regionList)){
			for (SysRegionDTO sysRegionDTO : regionList) {
				//TODO if(sysRegionDTO.getRgnLvl().equals(Integer.valueOf(SysRegionConstant.SYS_RGN_LVL_CONTY))){
					if(!sysRegionDTO.getRgnLvl().equals(Integer.valueOf(3))){
						rgnList.add(sysRegionDTO);
				}
			}
		}
//TODO		return this.getMenuTree(regionList, SysRegionConstant.SYS_RGN_CD_PID);
		return this.getMenuTree(rgnList, 0L);
	}
	
	private JSONArray getMenuTree(List<SysRegionDTO> list, Long rgnPid){
		JSONArray tree = new JSONArray();
		for (SysRegionDTO sysRegionDTO : list) {
			JSONObject obj = new JSONObject();
			obj.put("rgnCd", sysRegionDTO.getRgnCd());	//区域代码
			obj.put("rgnNm", sysRegionDTO.getRgnNm());//区域名称
			Long id = sysRegionDTO.getId();
			Long pid = sysRegionDTO.getRgnPid();
			if(rgnPid.equals(pid)){
				JSONArray childTree = this.getMenuTree(list, id);
				if(childTree.size()==0){
					obj.put("children", null);
					tree.add(obj);
				}else{
					obj.put("children", childTree);
					tree.add(obj);
				}
			}
		}
		return tree;
	}
	

	@Override
	public List<Long> getIsUseQuatPrpsAttr(PrjQuatPrpsAttrQueryCondition qc) throws BaseException {
		if(null==qc) return null;
		
		return this.projectApiService.getIsUseQuatPrpsAttr(qc);
	}
	
	@Override
	public JSONArray searchOrgCdJSONArray() throws BaseException {
		List<SysOrgDTO> sysOrgDTOList = this.sysOrgApiService.searchSysBuOrgListWithChild(SysOrgConstant.SYS_ORG_ORG_TYP_CD_IS_BUSI, CurrentThreadContext.getCurrentSysCd());
		logger.info("获取组织结构下拉树,sysOrgDTOList:{}",JSON.toJSONString(sysOrgDTOList));
		return this.getOrgCdMenuTree(sysOrgDTOList, 1L);
	}
	
	private JSONArray getOrgCdMenuTree(List<SysOrgDTO> list, Long orgPid){
		JSONArray tree = new JSONArray();
		for (SysOrgDTO sysOrgDTO : list) {
			JSONObject obj = new JSONObject();
			obj.put("orgCd", sysOrgDTO.getOrgCd());
			obj.put("orgNm", sysOrgDTO.getOrgNm());
			Long id = sysOrgDTO.getId();
			Long pid = sysOrgDTO.getOrgPid();
			if(orgPid.equals(pid)){
				JSONArray childTree = this.getOrgCdMenuTree(list, id);
				if(childTree.size()==0){
					obj.put("children", null);
					tree.add(obj);
				}else{
					obj.put("children", childTree);
					tree.add(obj);
				}
			}
		}
		return tree;
	}
}
